/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.collection.CollUtil
 *  cn.hutool.core.util.StrUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.TextField
 *  javafx.stage.Stage
 */
package com.gys.controller.rechargecard;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.gys.common.business.MemberCardUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.util.SpringUtil;
import com.gys.controller.BaseController;
import com.gys.controller.rechargecard.RechargeCardExchangeController;
import com.gys.controller.rechargecard.RechargecardController;
import com.gys.data.enumclass.Sex;
import com.gys.data.member.MemberCardInData;
import com.gys.data.member.MemberCardOutData;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.Collection;
import java.util.List;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

@FXMLController
public class MemberCardQueryController
extends BaseController
implements Initializable {
    @FXML
    private TextField memberCardId;
    @FXML
    private TextField client;
    @FXML
    private TextField mobileQuery;
    @FXML
    private TextField changeRemark;
    private MemberCardOutData outData;
    private Object currentController;

    public void initialize(URL location, ResourceBundle resources) {
        RechargecardController rechargecardController = (RechargecardController)SpringUtil.getBean("rechargecardController");
        RechargeCardExchangeController exchangeController = (RechargeCardExchangeController)SpringUtil.getBean("rechargeCardExchangeController");
        if (rechargecardController.isForward()) {
            this.currentController = rechargecardController;
            rechargecardController.setForward(false);
        } else if (exchangeController.isForward()) {
            this.currentController = exchangeController;
            exchangeController.setForward(false);
        }
    }

    @FXML
    private void getMemberCardInfo() {
        Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", null);
        String mobile = this.mobileQuery.getText();
        if (StrUtil.isBlank((CharSequence)mobile)) {
            alert.setContentText("\u8bf7\u8f93\u5165\u624b\u673a\u53f7\u7801");
            alert.showAndWait();
            return;
        }
        MemberCardInData inData = new MemberCardInData();
        inData.setGsmbMobile(mobile);
        HttpJson rsp = MemberCardUtil.getMemberCardList(inData);
        if (rsp.isSuccess()) {
            List dataList = JSON.parseArray((String)rsp.getMsg(), MemberCardOutData.class);
            if (CollUtil.isEmpty((Collection)dataList)) {
                this.outData = new MemberCardOutData();
                this.memberCardId.setText("");
                this.client.setText("");
                alert.setContentText("\u672a\u67e5\u8be2\u5230\u76f8\u5173\u4f1a\u5458\u5361");
                alert.showAndWait();
                return;
            }
            this.outData = (MemberCardOutData)dataList.get(0);
            this.memberCardId.setText(this.outData.getGsmbCardId());
            this.client.setText(this.outData.getClientName());
        } else {
            alert.setContentText(rsp.getMsg());
            alert.showAndWait();
        }
    }

    @FXML
    private void useMemberCardId() {
        String cardId = this.memberCardId.getText();
        Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", null);
        if (StrUtil.isBlank((CharSequence)cardId)) {
            alert.setContentText("\u8bf7\u5148\u67e5\u8be2\u4f1a\u5458\u5361");
            alert.showAndWait();
        } else {
            if (this.currentController instanceof RechargecardController) {
                ((RechargecardController)this.currentController).getGsrcIdSave().setText(cardId);
                ((RechargecardController)this.currentController).getGsrcNameSave().setText(this.outData.getGsmbName());
                ((RechargecardController)this.currentController).getGsrcMobileSave().setText(this.outData.getGsmbMobile());
                if (Sex.MALE.getId().equals(this.outData.getGsmbSex())) {
                    ((RechargecardController)this.currentController).getGsrcSexSave().setValue(Sex.MALE);
                } else {
                    ((RechargecardController)this.currentController).getGsrcSexSave().setValue(Sex.FEMALE);
                }
                ((RechargecardController)this.currentController).getGsrcTelSave().setText(this.outData.getGsmbTel());
                ((RechargecardController)this.currentController).getGsrcAddressSave().setText(this.outData.getGsmbAddress());
                ((RechargecardController)this.currentController).initPayInfo();
            } else if (this.currentController instanceof RechargeCardExchangeController) {
                ((RechargeCardExchangeController)this.currentController).getExchangeNewCardNo().setText(cardId);
            }
            this.getStage().close();
        }
    }

    @FXML
    private void closeWindow() {
        this.getStage().close();
    }

    private Stage getStage() {
        Stage stage = null;
        if (this.currentController instanceof RechargecardController) {
            stage = ((RechargecardController)this.currentController).getStg();
        } else if (this.currentController instanceof RechargeCardExchangeController) {
            stage = ((RechargeCardExchangeController)this.currentController).getStg();
        }
        return stage;
    }
}

